﻿using Authorization.Center.Controllers;
using Authorization.Center.Dto;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Breed.ApI.Application.Command;
using S.Breed.Domain;
using S.Common.Enums;
using S.Common.Enums.BreedEnum;
using Serilog;
using static S.Breed.ApI.Application.Command.MaternalMatingCommand;

namespace S.Breed.ApI.Controllers
{
    /// <summary>
    /// 种母配种写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaternalMatingController : BaseController
    {
        private readonly IMediator mediator;
        public MaternalMatingController(IMediator mediator,MySqlDbContext _db) : base(_db)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 配种新增
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult>  AddMaternalMating(AddMaternalMatingCommand command)
        {
            foreach (var item in command.MaternalMatings)
            {
                item.CreateBy = UserStrategyDto.UserTrueName;
            }
            return Ok(await mediator.Send(command));
        
        
        }
        /// <summary>
        /// 配种修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdMaternalMating(UpdMaternalCommand command)
        {
            command.UpdateBy = UserStrategyDto.UserTrueName;
            return Ok(await mediator.Send(command));


        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="ear"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdateState(string ear)
        {
            var command = new UpdateStateCommand(ear);
            var result = await mediator.Send(command);
            return Ok(result); // 返回修改的记录数或其他相关信息
        }
        /// <summary>
        /// 修改回状态
        /// </summary>
        /// <param name="ear"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdateHuiState(string ear)
        {
            var command = new UpdateHuiStateCommand(ear);
            var result = await mediator.Send(command);
            return Ok(result); // 返回修改的记录数或其他相关信息
        }
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdExamine(string id)
        {
            var command = new UpdExamineCommand(id);
            var result = await mediator.Send(command);
            return Ok(result); // 返回修改的记录数或其他相关信息
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpDelete]
        public async Task<IActionResult> DelMaternalMating(string ear)
        {
            var command = new DelMaternalCommand(ear);
            var result = await mediator.Send(command);
            return Ok(result);
        }
    }
}
